import { Component, OnInit } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { ActivatedRoute, Router } from '@angular/router';
import { ApiService } from '@core/api.service';
import { ClearLoginService } from '@core/clearLogin.service';
import { NzMessageService } from 'ng-zorro-antd';
import { LocalStorage } from '@core/local.storage';
import { environment } from '../../../../environments/environment';

@Component({
  selector: 'app-xtbg.component',
  templateUrl: './xtbg.component.html',
  styleUrls: ['./xtbg.component.less']
})

export class XtbgComponent implements OnInit {
  username: any;
  orgname: any;
  orgid: any;
  menuList: any = [];

  constructor(
    private http: _HttpClient,
    private router: Router,
    private apiService: ApiService,
    public clearLoginService: ClearLoginService,
    public msg: NzMessageService,
    public ls: LocalStorage,
  ) { }

  ngOnInit(): void {
    const loginInfo = JSON.parse(this.ls.get('loginInfo'));
    this.username = loginInfo.VC_NAME;
    this.orgname = loginInfo.VC_ORG$NAME;
    this.orgid = loginInfo.VC_ORG$ID;

    switch (loginInfo.N_LEVEL) {
      case 50:// 段
        this.menuList = [
          {
            "name": "段工作任务清单", "icon": "tool", "children": [
              { "name": "任务清单查询", "link": "zdrwgzqd/duanquery" },
              { "name": "工作任务清单", "link": "zdrwgzqd/edit" }
            ]
          },
          {
            "name": "车间工作任务清单", "icon": "tool", "children": [
              { "name": "任务清单查询", "link": "zdrwgzqd/chejianquery" }
            ]
          }
        ]
        break;
      case 30:// 车间
        this.menuList = [
          {
            "name": "段工作任务清单", "icon": "tool", "children": [
              { "name": "任务清单查询", "link": "zdrwgzqd/duanquery" }
            ]
          },
          {
            "name": "车间工作任务清单", "icon": "tool", "children": [
              { "name": "任务清单查询", "link": "zdrwgzqd/chejianquery" },
              { "name": "工作任务清单", "link": "zdrwgzqd/edit" }
            ]
          }
        ]
        break;
      case 10:// 工区
        this.menuList = [
          {
            "name": "段工作任务清单", "icon": "tool", "children": [
              { "name": "任务清单查询", "link": "zdrwgzqd/duanquery" }
            ]
          },
          {
            "name": "车间工作任务清单", "icon": "tool", "children": [
              { "name": "任务清单查询", "link": "zdrwgzqd/chejianquery" }
            ]
          }
        ]
        break;
    }
    this.menuList.push({
      "name": "审批流程", "icon": "setting", "children": [
        { "name": "审批流程查询", "link": "splc/cx" },
        { "name": "审批流程维护", "link": "splc/wh" }
      ]
    }, {
      "name": "图纸管理", "icon": "radar-chart", "children": [
        { "name": "CAD图纸查看", "link": "cadDrawings/view" },
        { "name": "CAD图纸维护", "link": "cadDrawings/edit" }
      ]
    }, {
      "name": "电缆径路", "icon": "file-image", "children": [
        { "name": "电缆径路查看", "link": "cableRoute/view" },
        { "name": "电缆径路维护", "link": "cableRoute/edit" }
      ]
    });
  }

  toMain() {
    this.router.navigate(['']);
  }
  logout() {
    this.loginOutAction().subscribe((res: any) => {
      if (res.type === 'success') {
        this.msg.success('退出成功', { nzDuration: 1000 });
        this.clearLoginService.clearAll();
        setTimeout(() => {
          this.router.navigate(['passport/login']);
        }, 500);
      } else {
        this.msg.success('退出失败', { nzDuration: 1000 });
      }
    });
  }
  // 退出
  loginOutAction() {
    const url = environment.apiBase + '/csmis/login/out.jwt';
    return this.http.post(url);
  }
}
